<template>
  <div class="dashboard-container">
    <aside class="aside-style">
      <el-row>
        <el-col :span="2">
          <el-button type="primary" size="mini" icon="el-icon-circle-plus" @click="addNewBanner">新增</el-button>
        </el-col>
      </el-row>
    </aside>
    <el-table
      :data="list"
      border
      highlight-current-row
      width="100%"
      style="margin-top: 20px;font-size:12px"
    >
      <el-table-column label="图片" align="center">
        <template slot-scope="scope">
          <img :src="scope.row.imgurl" alt="" class="img-style">
        </template>
      </el-table-column>
      <el-table-column label="权值" align="center">
        <template slot-scope="scope">
          <el-input v-model="scope.row.qz" placeholder="请输入内容" style="width:200px">
            <el-button slot="append" @click="resetQzFun(scope.row)">修改权值</el-button>
          </el-input>
        </template>
      </el-table-column>

      <el-table-column prop="url" label="路径" align="center" />

      <el-table-column label="操作" align="center">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="resetFun(scope.row)">修改</el-button>
          <del-confirm @onConfirm="delFun(scope.row)" />
        </template>
      </el-table-column>
    </el-table>
    <add-dialog ref="banner-dialog" @reloadFun="reloadFun" />
  </div>
</template>

<script>
import addDialog from '../set/components/banner-dialog'
import delConfirm from '@/components/DelConfirm/index'
import { getBannerListApi, deleletBannerApi, uploadBannerApi } from '@/api/main'
export default {
  components: {
    addDialog,
    delConfirm
  },
  data() {
    return {
      list: []
    }
  },
  created() {
    this.getBannerList()
  },
  methods: {
    getBannerList() {
      getBannerListApi().then(res => {
        this.list = res
      })
    },
    delFun(row) {
      console.log(row)
      const obj = row.imgurl.split('/')
      const data = {
        id: row.id,
        object: obj[obj.length - 1]
      }
      //   console.log(data)
      deleletBannerApi(data).then(res => {
        if (res.code === 200) {
          this.$message.success(res.msg)
          this.getBannerList()
        }
      })
    },
    resetFun(row) {
      this.$refs['banner-dialog'].dialogVisible = true
      this.$refs['banner-dialog'].title = '修改'
      this.$refs['banner-dialog'].form = row
    },
    addNewBanner() {
      console.log('banner')
      this.$refs['banner-dialog'].dialogVisible = true
      this.$refs['banner-dialog'].title = '新增'
      this.$refs['banner-dialog'].form = {
        id: '',
        imgurl: '',
        qz: '',
        url: ''
      }
    },
    reloadFun() {
      this.getBannerList()
    },
    resetQzFun(row) {
      console.log(row)
      const data = row
      uploadBannerApi(data).then(res => {
        console.log(res)
        if (res.code === 200) {
          this.$message.success(res.msg)
          this.getBannerList()
        } else {
          this.$message.warning(res.msg)
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.img-style {
    width: 5opx;
    height:50px;
}
.dashboard {
    &-container {
        margin: 30px;
    }
    &-text {
        font-size: 30px;
        line-height: 46px;
    }
}
</style>
